<template>
  <div class="container">
    <div class="main-body">
      <div class="row gutters-sm">
        <div class="card mb-3">
          <div class="card-body">
            <div class="row">
              <div class="col-sm-3">
                <h6 class="mb-0">Имя</h6>
              </div>
              <div class="col-sm-9 text-secondary">{{ user.name }}</div>
            </div>
            <hr />
            <div class="row">
              <div class="col-sm-3">
                <h6 class="mb-0">Email</h6>
              </div>
              <div class="col-sm-9 text-secondary">{{ user.email }}</div>
            </div>
            <hr />
            <div class="row">
              <div class="col-sm-3">
                <h6 class="mb-0">Организация</h6>
              </div>
              <div class="col-sm-9 text-secondary">
                {{ user.organization.name }}
              </div>
            </div>
            <hr />
            <div class="row">
              <div class="col-sm-3">
                <h6 class="mb-0">ИНН</h6>
              </div>
              <div class="col-sm-9 text-secondary">
                {{ user.organization.inn }}
              </div>
            </div>
            <hr />
            <div class="row">
              <div class="col-sm-3">
                <h6 class="mb-0">Роль</h6>
              </div>
              <div class="col-sm-4 d-flex">
                <select v-if="is_changing" class="form-control" v-model="role" aria-label="Default select example">
                  <option v-if="user.role != 'user'" :value="'user'">User</option>
                  <option v-if="user.role != 'admin'" :value="'admin'">Admin</option>
                </select>
                <div class="me-3" v-else>
                  {{ user.role }}
                </div>
                <div v-if="you.role != 'user'">
                  <button v-if="!is_changing" @click="is_changing = true" class="btn btn-primary mb-3">
                    Изменить
                  </button>
                  <button v-else @click="$emit('changeRole', role); is_changing = false">Сохранить</button>
                </div>

              </div>
            </div>
            <!-- <hr />
              <div class="row">
                <div class="col-sm-12">
                  <button class="btn btn-info">Изменить</button>
                </div>
              </div> -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    you: Object,
    user: Object,
  },
  emits: ['changeRole'],
  data() {
    return {
      is_changing: false,
      role: ''
    }
  },
};
</script>

<style></style>